import 'package:ladder_cash/app/app.dart';
import 'package:ladder_cash/app/com/http/http_request.dart';
import 'package:ladder_cash/app/key_mix.dart';
import 'package:get/get.dart';

import '../../../library/src/logger.dart';

class OrderLogic extends GetxController {
  List<String> get tabNames => App.localeEn
      ? ['In progress', 'Repayment', 'Finished']
      : ["En progreso", "Reembolso", "Finalizado"]; //'All',
  static int tabIndex = 0;

  int page = 1;

  var agree = true;

  changeAgree(){
    agree = !agree;
    update();
  }

  List? orders;

  @override
  onInit() {
    try {
      if (tabIndex == 0) {
        tabIndex = Get.arguments['tabIndex'];
      }
    } catch (e) {}
  }

  refreshData() {
    page = 1;
    orders = null;
    update();
    return;
  }


  Future<List?> getData() async {
    var dataForm = {
      'pageNum'.hx: page,
      'pageSize'.hx: 20,
      'orderType'.hx: [7, 6, 5][tabIndex], // 4全部 7进行中 6待还款 5已结清
    };

    var data =
    await HttpRequest().post('/v3/personal-center/order-list'.hx, dataForm);
    if (data == null) {
      page = 1;
      return orders = null;
    }
    if (page == 1) {
      orders = data['list'.hx] ?? [];
    } else {
      orders?.addAll(data['list'.hx] ?? []);
    }
    return orders;
  }
}
